package com.xhwl.data.controller;

import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.config.FormData;
import com.xhwl.common.query.FormQuery;
import com.xhwl.data.service.IFormService;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: luyi
 * @Description:
 * @Date: Create in 17:22 2021/5/20
 */
@RestController
public class FormDataController {

    @Autowired
    private IFormService formService;

    @RequestMapping(value = "/form/data")
    public ResultJson formDate(@RequestHeader Short industryId, @RequestBody FormQuery formQuery){
        formQuery.withIndustryId(industryId);
        List<FormData> formData = formService.listFormData(formQuery);
        if(formData.isEmpty()){
            return ResultJson.success(Collections.emptyList());
        }
        List<FormDataView> collect = formData.stream().map(f -> {
            FormDataView formDataView = new FormDataView();
            BeanUtils.copyProperties(f, formDataView);
            return formDataView;
        }).collect(Collectors.toList());
        return ResultJson.success(collect);
    }

    @Data
    class FormDataView{
        private Integer formId;

        private String engName;

        private String chnName;

    }
}


